package com.findyou.mapper;

import com.findyou.entity.Orders;
import com.findyou.entity.User;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @Title: OrdersMapper
 * @Author 贾金博
 * @Package com.findyou.mapper
 * @Date 2024/11/3 上午9:13
 * @description: 订单mapper接口
 */
public interface OrdersMapper {

    /**
     * 一对一的查询，查询一个订单以及订单的用户
     * @return
     */
    @Select("select * from orders")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "ordertime", property = "ordertime"),
            @Result(column = "total", property = "total"),
            @Result(property = "user", javaType = User.class,
                    column = "uid", one = @One(select = "com.findyou.mapper.UserMapper.getUserById",
                    fetchType = FetchType.EAGER /*结束懒加载*/
            )
            )
    })
    List<Orders>findAllWithUser();

    /**
     * 根据uid查询这个用户的全部订单
     * @param uid
     * @return
     */
    @Select("select * from orders where uid = #{uid}")
    public List<Orders>findOrdersByUid(Integer uid);

}
